#include "StdAfx.h"
#include "../Engine/TerrainTile.hpp"

namespace he
{
	TerrainTile::TerrainTile(unsigned short X, unsigned short Y)
		: m_X(X), m_Y(Y)
	{
	}

	void TerrainTile::set_deep(unsigned short Vertex, float Height, bool RecalculateNormals, bool Absolute)
	{
		if(Absolute)
			m_Deeps[Vertex] = Height / DEEP_RATIO;
		else
			m_Deeps[Vertex] += Height / DEEP_RATIO;
	}

	float TerrainTile::vertex_deep(unsigned short Vertex) const
	{
		return m_Deeps[Vertex];
	}

	void TerrainTile::set_vertex_deep(float V0, float V1, float V2, float V3)
	{
		m_Deeps[0] = V0;
		m_Deeps[1] = V1;
		m_Deeps[2] = V2;
		m_Deeps[3] = V3;
	}

	void TerrainTile::set_terrain_type_for_vertex(unsigned short Vertex, unsigned short Type)
	{
		assert(Vertex <= 4 && "Vertex out of index");
		m_TerrainTypeArray[Vertex] = Type;
	}

	unsigned short TerrainTile::get_terrain_type(unsigned short Vertex) const
	{
		assert(Vertex <= 4 && "Vertex out of index");
		return m_TerrainTypeArray[Vertex];
	}

	float TerrainTile::get_tile_width()
	{
		// sqrt(2)/2
		return 0.70710678118654752440084436210485f;

	}

	float TerrainTile::get_tile_height()
	{
		return get_tile_width();
	}
}